home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / EnterAct Stuff / Indent project / Indent Source / Code_Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-17  |  9.7 KB  |  390 lines  |  [TEXT/CWIE]

  1. /***********main file for Indent**************/
  2. /* This file contains the entry point for the code resource, and
  3. a bit of glue for the extension functions. From resource to resource
  4. all that varies is the name of the function called to do the real
  5. work - "InvokeHAWK" here.                 */
  6.  
  7. /* Copyright © 1986,1988,1989,1991,1992 the Free Software Foundation, Inc.
  8.  *         This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language, modified for the Macintosh (also called Indent).
  10.  *         GAWK is free software; you can redistribute or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 1, or any later version.
  13.  *         GAWK is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.  * GNU General Public License for more details.
  17.  *         You should have received a copy of the GNU General Public License
  18.  * along with GAWK; see the file "COPYING Indent". If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  * Written for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
  21.    Revised May 1992: new setup/restore a4 strategy.
  22.    Rev Apr 1995: converted over to Code Warrior
  23.  */
  24.  
  25. #ifdef powerc
  26. #include <CodeFragments.h>
  27. #else
  28. #include <A4Stuff.h>
  29. #endif
  30.  
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include "AppCodeComm.h"
  34.  
  35.  
  36. #ifndef NULL
  37. #define NULL        ((void *) 0)
  38. #endif
  39.  
  40. /* Global copy of the AppCodeComm struct passed from the application
  41. to the code resource - gacc stands for Global Application-Code resource
  42. Communication. Gacc.*/
  43. AppCodeComm    gacc;
  44.  
  45. /* Global to indicate if calling app's event loop has been made
  46. available and should call it */
  47. Boolean gConcurrent;
  48.  
  49. #ifndef powerc
  50. long _app_a4;
  51. #endif
  52. /* "main" call for the specific code resource */
  53. extern short InvokeIndent(void); /* see Hawk_Interface.c */
  54.  
  55. /* Protos for functions in this file */
  56. void main(ACCPtr ac);
  57. /* Callbacks, to be made available to other files */
  58. short InDictionary(char *tokenName);
  59. Boolean HasInDictionary(void);
  60. Handle GetFrontText(Boolean getItAll);
  61. Boolean HasGetFrontText(void);
  62. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  63.         short *vRefNumPtr, char *fileName, Boolean clearFlag);
  64. Boolean HasGetNextMultiFile(void);
  65. short OKStopAlert(Ptr cstringPtr);
  66. Boolean HasOKStopAlert(void);
  67. void MemoryAlert(void);
  68. Boolean HasMemoryAlert(void);
  69. short GetScreenHeight(void);
  70. Boolean HasGetScreenHeight(void);
  71. short GetScreenWidth(void);
  72. Boolean HasGetScreenWidth(void);
  73. void SetWatchCursor(void);
  74. Boolean HasSetWatchCursor(void);
  75. void DoEventLoopOnce(void);
  76. Boolean HasDoEventLoopOnce(void);
  77. Handle GetTheClip(void);
  78. Boolean HasGetTheClip(void);
  79. short PutTheClip(char *newClipStr);
  80. Boolean HasPutTheClip(void);
  81.  
  82. // Kludge required by CodeWarrior 6
  83.  void (*__exit_proc__)(void);
  84.  
  85. /* The "main" that is called from the running application. This file is
  86. kept small and in its own segment because lots of other things get piled
  87. into here as well - the jump table for the code resource, for example.
  88. So do the bare minimum - set up the global register reference, call the
  89. code resource main function, pass back a result code, and restore the
  90. a4 register. Functions below main() are the extension interface
  91. functions, which must be in this file to make use of the little functions
  92. above that save and restore a4. They all check to see that the extension
  93. in question has been passed from the application, and if not either return
  94. a zero or NULL or return a safe general value. No extension should be
  95. essential to the operation of the code resource.
  96. */
  97. /* results:
  98. <= -3 : counts as -1 at present
  99. -2 : show stderr
  100. -1 : user cancelled or error during dialog - no run
  101. 0  : run OK, do nothing special after
  102. 1  : show stdout
  103. 2  : show and select stdout
  104. > 2 : no action at present (counts as equivalent to 0)
  105. */
  106. void main(ACCPtr ac)
  107.     {
  108.     short    result;
  109. #ifndef powerc
  110.     long     _app_a4 = SetCurrentA4();    //sets A4 to point to your code resources globals
  111.                                     //it returns what's currently in A4 so you can restore it later
  112.                                     //SetCurrentA4 and SetA4 are analogous to SetCurrentA5 and SetA5
  113. #endif
  114.     
  115.     /* Uncomment this for a version "sanity check": **************
  116.     if (ac->version < 0 || ac->version > 100)
  117.         {
  118.         OKStopAlert("Version number passed by calling application \
  119. is impossible. Please fix the application before trying again.");
  120.         ac->result = -1;
  121.         (void)SetA4(_app_a4);
  122.         return;
  123.         }
  124.     ********** end version check */
  125.  
  126.     gacc = *ac; /* make a global copy */
  127.  
  128.     if (gacc.version <= 1)
  129.         {
  130.         gacc.DoEventLoopOnce_Ext = NULL;
  131.         gacc.GetAppClip_Ext = NULL;
  132.         }
  133.     if (HasDoEventLoopOnce())
  134.         gConcurrent = TRUE;
  135.     else
  136.         gConcurrent = FALSE;
  137.     
  138.     /* call 'true' main of code resource */
  139.     result = InvokeIndent();
  140.     ac->result = result;
  141. #ifndef powerc
  142.     //Reset A4 to what it was when we entered.  The return value (which we ignore) is our
  143.     //global pointing A4.
  144.     (void)SetA4(_app_a4);
  145.     /* return nothing - communication via (ga)ac->result */
  146. #endif
  147.     }
  148.  
  149. /* Extension functions. See Call_Resource.c for details
  150. on what these do. EnterAct supplies them all, but your application
  151. doesn't have to supply any of them, and your code resource should
  152. not rely on any of them being available.
  153.  
  154. A Boolean companion function for each extension reports whether
  155. the extension is available for use. 
  156. */
  157.  
  158. short InDictionary(char *tokenName)
  159.     {
  160.     ACCPtr    laccp = &gacc; /* must use a local pointer if 68K */
  161.     short    ret;
  162. #ifndef powerc
  163.     long cura4 = SetA4(_app_a4);
  164. #endif
  165.     if (laccp->InDictionary_Ext != NULL)
  166.         ret = (*(laccp->InDictionary_Ext))(tokenName);
  167.     else
  168.         ret = 0;
  169. #ifndef powerc
  170.     (void)SetA4(cura4);
  171. #endif
  172.     return(ret);
  173.     }
  174.  
  175. Boolean HasInDictionary()
  176.     {
  177.     return(gacc.InDictionary_Ext != NULL);
  178.     }
  179.  
  180. Handle GetFrontText(Boolean getItAll)
  181.     {
  182.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  183.     Handle    ret;
  184. #ifndef powerc
  185.     long cura4 = SetA4(_app_a4);
  186. #endif
  187.     if (laccp->GetFrontText_Ext != NULL)
  188.         ret = (*(laccp->GetFrontText_Ext))(getItAll);
  189.     else
  190.         ret = NULL;
  191. #ifndef powerc
  192.     (void)SetA4(cura4);
  193. #endif
  194.     return(ret);
  195.     }
  196.  
  197. Boolean HasGetFrontText()
  198.     {
  199.     return(gacc.GetFrontText_Ext != NULL);
  200.     }
  201.  
  202. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  203.         short *vRefNumPtr, char *fileName, Boolean clearFlag)
  204.     {
  205.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  206. #ifndef powerc
  207.     long cura4 = SetA4(_app_a4);
  208. #endif
  209.     if (laccp->GetNextMultiFile_Ext != NULL)
  210.         (*(laccp->GetNextMultiFile_Ext))(panePtr, indexPtr,
  211.             vRefNumPtr, fileName, clearFlag);
  212.     else
  213.         *indexPtr = -1;
  214. #ifndef powerc
  215.     (void)SetA4(cura4);
  216. #endif
  217.     }
  218.  
  219. Boolean HasGetNextMultiFile()
  220.     {
  221.     return(gacc.GetNextMultiFile_Ext != NULL);
  222.     }
  223.  
  224. short OKStopAlert(Ptr cstringPtr)
  225.     {
  226.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  227.     short    ret;
  228. #ifndef powerc
  229.     long cura4 = SetA4(_app_a4);
  230. #endif
  231.     if (laccp->OKStopAlert_Ext != NULL)
  232.         ret = (*(laccp->OKStopAlert_Ext))(cstringPtr);
  233.     else
  234.         ret = 0;
  235. #ifndef powerc
  236.     (void)SetA4(cura4);
  237. #endif
  238.     return(ret);
  239.     }
  240.  
  241. Boolean HasOKStopAlert()
  242.     {
  243.     return(gacc.OKStopAlert_Ext != NULL);
  244.     }
  245.  
  246. void MemoryAlert()
  247.     {
  248.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  249. #ifndef powerc
  250.     long cura4 = SetA4(_app_a4);
  251. #endif
  252.     if (laccp->MemoryAlert_Ext != NULL)
  253.         (*(laccp->MemoryAlert_Ext))();
  254. #ifndef powerc
  255.     (void)SetA4(cura4);
  256. #endif
  257.     }
  258.  
  259. Boolean HasMemoryAlert()
  260.     {
  261.     return(gacc.MemoryAlert_Ext != NULL);
  262.     }
  263.  
  264. short GetScreenHeight()
  265.     {
  266.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  267.     short        ret;
  268. #ifndef powerc
  269.     long cura4 = SetA4(_app_a4);
  270. #endif
  271.     if (laccp->GetScreenHeight_Ext != NULL)
  272.         ret = (*(laccp->GetScreenHeight_Ext))();
  273.     else
  274.         ret = 342; /* minimum possible */
  275. #ifndef powerc
  276.     (void)SetA4(cura4);
  277. #endif
  278.     return(ret);
  279.     }
  280.  
  281. Boolean HasGetScreenHeight()
  282.     {
  283.     return(gacc.GetScreenHeight_Ext != NULL);
  284.     }
  285.  
  286. short GetScreenWidth()
  287.     {
  288.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  289.     short        ret;
  290. #ifndef powerc
  291.     long cura4 = SetA4(_app_a4);
  292. #endif
  293.     if (laccp->GetScreenWidth_Ext != NULL)
  294.         ret = (*(laccp->GetScreenWidth_Ext))();
  295.     else
  296.         ret = 512; /* minimum possible */
  297. #ifndef powerc
  298.     (void)SetA4(cura4);
  299. #endif
  300.     return(ret);
  301.     }
  302.  
  303. Boolean HasGetScreenWidth()
  304.     {
  305.     return(gacc.GetScreenWidth_Ext != NULL);
  306.     }
  307.  
  308. void SetWatchCursor()
  309.     {
  310.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  311. #ifndef powerc
  312.     long cura4 = SetA4(_app_a4);
  313. #endif
  314.     if (laccp->SetWatchCursor_Ext != NULL)
  315.         (*(laccp->SetWatchCursor_Ext))();
  316. #ifndef powerc
  317.     (void)SetA4(cura4);
  318. #endif
  319.     }
  320.  
  321. Boolean HasSetWatchCursor()
  322.     {
  323.     return(gacc.SetWatchCursor_Ext != NULL);
  324.     }
  325.  
  326. void DoEventLoopOnce()
  327.     {
  328.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  329. #ifndef powerc
  330.     long cura4 = SetA4(_app_a4);
  331. #endif
  332.     if (laccp->DoEventLoopOnce_Ext != NULL)
  333.         (*(laccp->DoEventLoopOnce_Ext))();
  334. #ifndef powerc
  335.     (void)SetA4(cura4);
  336. #endif
  337.     }
  338.  
  339. Boolean HasDoEventLoopOnce()
  340.     {
  341.     return(gacc.DoEventLoopOnce_Ext != NULL);
  342.     }
  343.  
  344. Handle GetTheClip()
  345.     {
  346.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  347.     Handle    ret;
  348. #ifndef powerc
  349.     long cura4 = SetA4(_app_a4);
  350. #endif
  351.     if (laccp->GetAppClip_Ext != NULL)
  352.         ret = (*(laccp->GetAppClip_Ext))();
  353.     else
  354.         ret = NULL;
  355. #ifndef powerc
  356.     (void)SetA4(cura4);
  357. #endif
  358.     return(ret);
  359.     }
  360.  
  361. Boolean HasGetTheClip()
  362.     {
  363.     return(gacc.GetAppClip_Ext != NULL);
  364.     }
  365.  
  366. // Note for version 3 the version is signalled by long extendID == 'VER3'
  367. // inside gacc -- for previous versions, the odds of this long being set
  368. // to exactly 'VER3' are very small.
  369.  
  370. short PutTheClip(char *newClipStr)
  371.     {
  372.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  373.     short    ret = 0;
  374. #ifndef powerc
  375.     long cura4 = SetA4(_app_a4);
  376. #endif
  377.     if (laccp->extendID == 'VER3' && laccp->PutAppClip_Ext != NULL)
  378.         ret = (*(laccp->PutAppClip_Ext))(newClipStr);
  379. #ifndef powerc
  380.     (void)SetA4(cura4);
  381. #endif
  382.     return(ret);
  383.     }
  384.  
  385. Boolean HasPutTheClip(void)
  386.     {
  387.     return(gacc.extendID == 'VER3' && gacc.PutAppClip_Ext != NULL);
  388.     }
  389.  
  390.